package com.itheima.dubbo.web;

import com.itheima.dubbo.UserInterface;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboReference;

import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {

    @DubboReference(retries = 2,cluster = "failfast")
    UserInterface userInterface;

    @GetMapping("hello")
    public String Hello(String username){
        return userInterface.hello(username);
    }
    @GetMapping("findOner/{id}")
    public User findOne(@PathVariable("id") Long id){
        RpcContext.getContext().setAttachment("company","itheima");
        return userInterface.findOne(id);
    }
}
